#!/usr/bin/env python
# coding:utf-8
# @author heitfei

"""
twisted reactor server
"""

from twisted.internet import protocol, reactor
import time

PORT = 9000

class TSServProtocol(protocol.Protocol):
    def connectionMade(self):
        client = self.clnt = self.transport.getPeer().host
        print '...connected from:',client

    def dataReceived(self, data):
        self.transport.write('[%s] %s' % (time.ctime(), data))

factory = protocol.Factory()
factory.protocol = TSServProtocol
print 'waiting for connection...'
reactor.listenTCP(PORT, factory)
reactor.run()